home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / FinderGrok / osa stuff / CCWDisplayLine.cp < prev    next >
Text File  |  2000-06-23  |  4KB  |  149 lines

  1. // =================================================================================
  2. //    CCWDisplayLine.cp                    ©1996-1999 Metrowerks Inc. All rights reserved.
  3. // =================================================================================
  4.  
  5. using namespace std;
  6.  
  7. #include "CCWDisplayLine.h"
  8. #include "MoreOSA.h"
  9. #include "CAEDescriptor.h"
  10. #include "Str255.h"
  11. #include "SelectFile.h"
  12.  
  13. SelectFile theSelectorStuff;
  14.  
  15. static Boolean firstTime = true;
  16. bool    TestParse(FSSpec *theSpec)
  17. {
  18.     return theSelectorStuff.PaternMatch(theSpec->name);
  19. }
  20.  
  21. #ifdef CONDUIT
  22. #include "CConduitDialog.h"
  23. static pascal Boolean defaultIdleProc(EventRecord *eventRecord, long *sleepTime, RgnHandle *mouseRegion)
  24. {
  25.     return CConduitDialog::AEIdleProc(eventRecord, sleepTime, mouseRegion);
  26. }
  27.  
  28. #else
  29.  
  30. static pascal Boolean defaultIdleProc(EventRecord *eventRecord, long *sleepTime, RgnHandle *mouseRegion)
  31. {
  32.     if (firstTime) {
  33.         *sleepTime = 30;
  34.         *mouseRegion = 0;
  35.         firstTime = 0;
  36.     }
  37.     LEventDispatcher *eventD = LEventDispatcher::GetCurrentEventDispatcher();
  38.     if (eventD != 0) {
  39.         eventD->DispatchEvent(*eventRecord);
  40.     }
  41.     return false;
  42. }
  43. #endif
  44.  
  45. static AEIdleUPP    gDefaultIdleProc = NewAEIdleProc(defaultIdleProc);
  46.  
  47. Handle    CCWDisplayLine::gDisplayScript = 0; 
  48.  
  49.  
  50. CCWDisplayLine::CCWDisplayLine(const string& fileName, SInt32 lineToDisplay)
  51.     : fFileName(fileName), fLineToDisplay(lineToDisplay)
  52. {
  53. }
  54.  
  55. void
  56. CCWDisplayLine::Display()
  57. {
  58.     AEKeyword keyWord;
  59.     DescType typeCode;
  60.     int        theInt;
  61.     Size    actualSize;
  62.     OSErr    err;
  63.     Rect    testRect;
  64.     int        theLeft, theTop, theRight, theBottom;
  65.  
  66.     theSelectorStuff.Run();
  67.  
  68.     if (gDisplayScript == 0) {
  69.         CompileDisplayScript();
  70.     }
  71.     
  72.     ScriptObject script;
  73.     script.SetIdleProc(gDefaultIdleProc);
  74.     script.Load(gDisplayScript);
  75.     
  76.     CAEDescriptor params;
  77. //    CAEDescriptor fileNameDesc(AsStr255(fFileName));
  78.     CAEDescriptor lineToDisplayDesc(fLineToDisplay);
  79.  
  80.     ThrowIfOSErr_( AECreateList(NULL, 0, false, params) );
  81. //    ThrowIfOSErr_( AEPutDesc(params, 1, fileNameDesc) );
  82.     ThrowIfOSErr_( AEPutDesc(params, 1, lineToDisplayDesc) );
  83.  
  84.     script.CallSubroutine("displaywindowlocation", params);
  85.     CAEDescriptor    result;
  86.     CAEDescriptor    outList;
  87.     ThrowIfOSErr_( AECreateList(NULL, 0, false, outList) );
  88.  
  89.  
  90.     script.ReturnResults(result);
  91.     err = AEGetNthPtr(result, 1, typeInteger, &keyWord, &typeCode, &theLeft, sizeof(theInt), &actualSize);
  92.     err = AEGetNthPtr(result, 2, typeInteger, &keyWord, &typeCode, &theTop, sizeof(theInt), &actualSize);
  93.     err = AEGetNthPtr(result, 3, typeInteger, &keyWord, &typeCode, &theRight, sizeof(theInt), &actualSize);
  94.     err = AEGetNthPtr(result, 4, typeInteger, &keyWord, &typeCode, &theBottom, sizeof(theInt), &actualSize);
  95.  
  96.     SetRect(&testRect, theLeft, theTop, theRight, theBottom);
  97.     
  98.     long    outCount = 0;
  99.     long    theCount;
  100.     int        i;
  101.     FSSpec    testSpec;
  102.     
  103.     script.CallSubroutine("getfilelist", params);
  104.     script.ReturnResults(result);
  105.     err = AECountItems(result, &theCount);
  106.     for (i = theCount; i >= 1; i--)
  107.     {
  108.         err = AEGetNthPtr(result, i, typeFSS, &keyWord, &typeCode, &testSpec, sizeof(testSpec), &actualSize);
  109.         if (err == noErr)
  110.         {
  111.         
  112.             if (TestParse(&testSpec) == false)
  113.             {
  114.                 err = AEDeleteItem(result, i);
  115. //                CAEDescriptor    newDesc;
  116. //                err = AEGetNthDesc(outList, (long) i, /*'docf'*/typeWildCard, &keyWord, newDesc);
  117. //                err = AEPutDesc(outList, outCount, newDesc);
  118.             }
  119.             else
  120.                 outCount++;
  121.         }
  122.     }
  123.     
  124.     if (outCount > 0)
  125.     {
  126.         CAEDescriptor params2;
  127.         
  128.         ThrowIfOSErr_( AECreateList(NULL, 0, false, params2) );
  129.     //    ThrowIfOSErr_( AEPutDesc(params2, 1, outList) );
  130.         ThrowIfOSErr_( AEPutDesc(params2, 1, result) );
  131.         ThrowIfOSErr_( AEPutDesc(params2, 2, lineToDisplayDesc) );
  132.         
  133.         script.CallSubroutine("setfilelist", params2);
  134.     }
  135. }
  136.  
  137. ConstStringPtr kScriptFileName = "\pMacintosh HD:GrokScript";
  138.  
  139. void
  140. CCWDisplayLine::CompileDisplayScript()
  141. {
  142.     ScriptObject script;
  143.     
  144.     FSSpec scriptSpec;
  145.     ThrowIfOSErr_(::FSMakeFSSpec(0, 0, kScriptFileName, &scriptSpec));
  146.     script.Load(&scriptSpec);
  147.     gDisplayScript = script.Store((Handle)0);
  148.     HandToHand(&gDisplayScript);
  149. }